<template>
	<view class="main">
		<view class="active_tit">
			<view class="tit">
				商用车
			</view> 
			<!-- <view class="add">
				＋
			</view> -->
		</view>
		<!-- input -->
		<ActiveForm required  ref='tranNo'>
			<view class="active_label">
				道路运输经营许可证号：
			</view>
			<view class="active_input">
				<input type="text" v-model="stdOffsurSceneTruck.tranNo" />
			</view>
		</ActiveForm>
		
		<ActiveForm required  ref='specialNo'>
			<view class="active_label">
				特种运输资质许可证号：
			</view>
			<view class="active_input">
				<input type="text" v-model="stdOffsurSceneTruck.specialNo" />
			</view>
		</ActiveForm>
		
		<ActiveForm required  ref='tranYears'>
			<view class="active_label">
				物流运输行业经营或从业年限（月份数）：
			</view>
			<view class="active_input">
				<input type="number" v-model="stdOffsurSceneTruck.tranYears" />
			</view>
		</ActiveForm>
		
		<!-- <ActiveForm required  ref='stableGoods'>
			<view class="active_label">
				有无储备货源或稳定货源：
			</view>
			<view class="active_input">
				<SelectPicker v-model="stdOffsurSceneTruck.stableGoods" :options="stableGoodsOption" placeholder="请选择" />
			</view>
		</ActiveForm> -->
		
		<ActiveForm required  ref='affiliationFlag'>
			<view class="active_label">
				是否计划挂靠物流公司：
			</view>
			<view class="active_input">
				<SelectPicker v-model="stdOffsurSceneTruck.affiliationFlag" :options="affiliationFlagOption" placeholder="请选择" />
			</view>
		</ActiveForm>
		
		<ActiveForm required  ref='affiliationComps'>
			<view class="active_label">
				计划挂靠的物流公司：
			</view>
			<view class="active_input">
				<input disabled type="text" placeholder="请选择合作方" v-model="stdOffsurSceneTruck.affiliationComps" />
				<!-- <SelectPicker disabled @change='change1' v-model="stdOffsurSceneTruck.partnerNo" :options="options" placeholder="请选择合作方" /> -->
			</view>
		</ActiveForm>
		
		<ActiveForm required  ref='affiliationYears'>
			<view class="active_label">
				计划挂靠的期限（月份数）：
			</view>
			<view class="active_input">
				<input type="number" v-model="stdOffsurSceneTruck.affiliationYears" />
			</view>
		</ActiveForm>
		
		<!-- <ActiveForm required  ref='buyer'>
			<view class="active_label">
				购置人：
			</view>
			<view class="active_input">
				<input type="text" v-model="stdOffsurSceneTruck.buyer" />
			</view>
		</ActiveForm> -->
		<view class="active_tit">
			<view class="tit2">
				所要购置的商用车信息
			</view> 
			
		</view>
		<block v-for="(item,index) in stdOffsurSceneTruckDetail" :key='index'>
			<view class="cut">商用车{{index+1}} <uni-icons class="clear" type="clear" @click='stdDel(stdOffsurSceneTruckDetail,item,"stdOffsurSceneTruckDetail")'></uni-icons></view>
			<view class="main">
				<ActiveForm required  ref='truckType'>
					<view class="active_label">
						押品类型：
					</view>
					<view class="active_input">
						<SelectPicker v-model="item.collateralType" :options="ypType" placeholder="请选择" />
					</view>
				</ActiveForm>
				<ActiveForm   ref='carCode'>
					<view class="active_label">
						押品名称：
					</view>
					<view class="active_input">
						<input type="text" v-model="item.collateralName" />
						<button :disabled="item.flag" type="pg" @click="ypjy(item,index)">校验</button>
					</view>
				</ActiveForm>
				<ActiveForm required  ref='truckType'>
					<view class="active_label">
						押品编号：
					</view>
					<view class="active_input">
						<input disabled type="text" v-model="item.mortgageSystemId" />
					</view>
				</ActiveForm>
				<ActiveForm required  ref='truckType'>
					<view class="active_label">
						车辆类型：
					</view>
					<view class="active_input">
						<input type="text" v-model="item.truckType" />
					</view>
				</ActiveForm>
				<ActiveForm required  ref='truckModel'>
					<view class="active_label">
						品牌型号：
					</view>
					<view class="active_input">
						<input type="text" v-model="item.truckModel" />
					</view>
				</ActiveForm>
				
				<ActiveForm required  ref='dwt'>
					<view class="active_label">
						核载重量（吨）：
					</view>
					<view class="active_input">
						<mInput type="number" v-model="item.dwt" />
					</view>
				</ActiveForm>
				<!-- <ActiveForm required  ref=''>
					<view class="active_label">
						将要挂靠的公司：
					</view>
					<view class="active_input">
						
						<SelectPicker @change='change2($event,item)' v-model="item.partnerNo" :options="options" placeholder="请选择" />
					</view>
				</ActiveForm> -->
				<ActiveForm   ref='carCode'>
					<view class="active_label">
						车牌号：
					</view>
					<view class="active_input">
						<input type="text" v-model="item.carCode" />
						<button type="pg" @click="cpjy(item,index)">校验</button>
					</view>
				</ActiveForm>
				<ActiveForm   ref='vinNo'>
					<view class="active_label">
						车架号：
					</view>
					<view class="active_input">
						<input type="text" v-model="item.vinNo" />
					</view>
				</ActiveForm>
				<ActiveForm required  ref='truckValue'>
					<view class="active_label">
						可确切核实的购置凭证价值：
					</view>
					<view class="active_input">
						<mInput type="number" v-model="item.truckValue" />
					</view>
				</ActiveForm>
				<ActiveForm required  ref='truckMaxValue'>
					<view class="active_label">
						从公开渠道了解到的同一车型最高价值：
					</view>
					<view class="active_input">
						<mInput type="number" v-model="item.truckMaxValue" />
					</view>
				</ActiveForm>
				<ActiveForm required  ref='truckRealValue'>
					<view class="active_label">
						认定的购置价值：
					</view>
					<view class="active_input">
						<mInput type="number" v-model="item.truckRealValue" />
					</view>
				</ActiveForm>
				<ActiveForm required  ref='downPayRatio'>
					<view class="active_label">
						计划的首付比例：
					</view>
					<view class="active_input">
						<mInput  :thousand='false'  v-model="item.downPayRatio" />
					</view>
				</ActiveForm>
				<ActiveForm required  ref='downPayAmount'>
					<view class="active_label">
						计划的首付金额：
					</view>
					<view class="active_input">
						<mInput maxlength="16" type="number" v-model="item.downPayAmount" />
					</view>
				</ActiveForm>
				<ActiveForm required  ref='loanAmount'>
					<view class="active_label">
						计划的贷款金额：
					</view>
					<view class="active_input">
						<mInput maxlength="16" type="number" v-model="item.loanAmount" />
					</view>
				</ActiveForm>
			</view>
		</block>
		<view class="active_tit">
			<view class="tit2">
				
			</view> 
			<view class="add" @click="add">
				＋
			</view>
		</view>
	</view>
</template>

<script>
	import SelectPicker from "../../SelectPicker";
	import RegionPicker from "../../RegionPicker";
	export default {
		name: 'activeForm',
		props:{
			Pid:''
		},
		data() {
			return {
				province: "",
				city: "",
				county: "",
				index: 1,
				stdOffsurSceneTruck: {
					partnerNo:'',
					affiliationComp: "", //计划挂靠的物流公司
					affiliationFlag: "", //是否计划挂靠物流公司
					affiliationYears: 0, //计划挂靠的期限
					businessId: "", //业务申请流水号
					buyer: "", //购置人
					createTime: "", //创建时间
					createUser: "", //创建人
					customerId: "", //客户编号
					customerSystemId: "", //客户系统编号
					deleteFlag: "", //删除标志
					entityRoleType: "", //数据归属类型
					getDatTime: "", //数据加载时间
					imageUrl: "", //影像路径
					reqId: "", //业务申请序号
					sourceSystem: "", //数据来源系统
					specialNo: "", //特种运输资质许可证号
					stableGoods: "", //有无储备货源或稳定货源
					tranNo: "", //道路运输经营许可证号
					tranYears: 0, //物流运输行业经营或从业年限
					updateTime: "", //更新时间
					updateUser: "", //更新人
					uuid: "" //uuid
				},
				stdOffsurSceneTruckDetail:[
					{
						affiliationComp: "", //将要挂靠的公司
						businessId: "", //业务申请流水号
						createTime: "", //创建时间
						createUser: "", //创建人
						customerId: "", //客户编号
						customerSystemId: "", //客户系统编号
						deleteFlag: "", //删除标志
						downPayAmount: 0, //计划的首付金额
						downPayRatio: 0, //计划的首付比例
						dwt: 0, //核载重量（吨）
						entityRoleType: "", //数据归属类型
						getDatTime: "", //数据加载时间
						imageUrl: "", //影像路径
						loanAmount: 0, //计划的贷款金额
						reqId: "", //业务申请序号
						sourceSystem: "", //数据来源系统
						truckMaxValue: 0, //从公开渠道了解到的同一车型最高价值
						truckModel: "", //品牌型号
						truckRealValue: 0, //认定的购置价值
						truckType: "", //车辆类型
						truckValue: 0, //可确切核实的购置凭证价值
						updateTime: "", //更新时间
						updateUser: "", //更新人
						uuid: "", //uuid
						vinNo: "",//车架号
						carCode: "" //车牌号
					}
				],
				stableGoodsOption:[
					{
						label:'有',
						value:'01'
					},
					{
						label:'无',
						value:'02'
					}
				],
				affiliationFlagOption:[
					{
						label:'是',
						value:'01'
					},
					// {
					// 	label:'否',
					// 	value:'02'
					// }
				],
				ypType:[
					{
						label:'汽车-抵押',
						value:'E310101'
					},
				],
				options:[]
			}
		},
		mounted() {
			//获取返显数据
			setTimeout(()=>{    
				//数据反显
				this.stdOffsurSceneTruck = getApp().globalData.stdOffsurSceneTruck
				this.stdOffsurSceneTruckDetail = getApp().globalData.stdOffsurSceneTruckDetail
				//this.options = getApp().globalData.Partner
				for(let i=0;i<this.options.length;i++){
					this.options[i].label = this.options[i].partnerName
					this.options[i].value = this.options[i].partnerId
				}
			},getApp().globalData.timeout)
		},
		components: {
			SelectPicker,
			RegionPicker
		},
		watch:{
			Pid:{
				handler:function(res){
					this.stdOffsurSceneTruck.partnerNo = res.value
					this.stdOffsurSceneTruck.affiliationComps = res.label
				},
				deep:true
			},
			stdOffsurSceneTruck:{
				handler:function(res){
					//console.warn('stdOffsurSceneTruck组件数据变化',res)
					getApp().globalData.stdOffsurSceneTruck = res
				},
				deep:true
			},
			stdOffsurSceneTruckDetail:{
				handler:function(res){
					//console.warn('stdOffsurSceneTruckDetail组件数据变化',res)
					getApp().globalData.stdOffsurSceneTruckDetail = res
				},
				deep:true
			}
		},
		methods:{
			change1(e){
				//console.log(e)
				for(let i=0;i<this.options.length;i++){
					if(this.options[i].value===e){
						this.stdOffsurSceneTruck.affiliationComps = this.options[i].label
						break
					}
				}
			},
			change2(e,item){
				//console.log(e,item)
				for(let i=0;i<this.options.length;i++){
					if(this.options[i].value===e){
						item.affiliationComp = this.options[i].label
						break
					}
				}
			},
			ypjy(item,index){
				if (!item.collateralName) {
					uni.showToast({
						icon: 'none',
						title: '请输入押品名称',
						duration: 2000
					})
					return false
				}
				if (!item.vinNo) {
					uni.showToast({
						icon: 'none',
						title: '请输入车架号',
						duration: 2000
					})
					return false
				}
				//押品校验
				let data = {
					"idnfNo":item.vinNo,
					"reqId":getApp().globalData.reqId,
					"collatType": item.collateralType,
					"collatName":item.collateralName,
					"idnfName":"车架号码"
				  }
				this.sendRequest({
					url: 'loanBaseInfo/collateralIsUniqueOthers',
					method: 'post',
					hideLoading: true,
					data: data,
					complete: (res) => {
						console.log(res)
						if(res.data){
						   item.mortgageSystemId = res.data.COLL_REF
						   item.flag = true
							uni.showToast({
								title: '校验通过',
								icon: "none",
								duration: 2000
							})
						}else{
							item.carCode=''
							uni.showToast({
								title: '押品系统已存在该押品，请注意核对！',
								icon: "none",
								duration: 2000
							})
						}
					}
				}) 
			},
			cpjy(item,index){
				//接口查询车牌
				let data = {  
					"carNo":item.carCode,
					"carOwer": this.stdOffsurSceneTruck.affiliationComps,
				  }
				this.sendRequest({
					url: 'zoan/queryNameCheck',
					method: 'post',
					hideLoading: true,
					data: data,
					complete: (res) => {
						console.log(res)
						if(res.data){
						
							uni.showToast({
								title: '校验一致',
								icon: "none",
								duration: 2000
							})
						}else{
							item.carCode=''
							uni.showToast({
								title: '校验不一致，请重新输入',
								icon: "none",
								duration: 2000
							})
						}
					}
				})  
			},
			add(){
				this.stdOffsurSceneTruckDetail.push(
					{
						flag:false,
						collateralType:'E310101',
						mortgageSystemId:'',
						collateralName:'',
						affiliationComp: "", //将要挂靠的公司
						businessId: "", //业务申请流水号
						createTime: "", //创建时间
						createUser: "", //创建人
						customerId: "", //客户编号
						customerSystemId: "", //客户系统编号
						deleteFlag: "", //删除标志
						downPayAmount: 0, //计划的首付金额
						downPayRatio: 0, //计划的首付比例
						dwt: 0, //核载重量（吨）
						entityRoleType: "", //数据归属类型
						getDatTime: "", //数据加载时间
						imageUrl: "", //影像路径
						loanAmount: 0, //计划的贷款金额
						reqId: "", //业务申请序号
						sourceSystem: "", //数据来源系统
						truckMaxValue: 0, //从公开渠道了解到的同一车型最高价值
						truckModel: "", //品牌型号
						truckRealValue: 0, //认定的购置价值
						truckType: "", //车辆类型
						truckValue: 0, //可确切核实的购置凭证价值
						updateTime: "", //更新时间
						updateUser: "", //更新人
						uuid: "", //uuid
						vinNo: "", //车架号
						carCode: "" //车牌号
					}
				)
			}
		}
	}
</script>

<style lang="scss">
	
	
</style>


